package com.ktgj.train.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.train.domain.TrainOrderstatus;
import com.ktgj.train.service.ITrainOrderstatusService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 订单状态Controller
 * 
 * @author ruoyi
 * @date 2021-11-29
 */
@ControllerAdvice
@RestController
@RequestMapping("/orderstatus")
public class TrainOrderstatusController extends BaseController
{
    @Autowired
    private ITrainOrderstatusService trainOrderstatusService;

    /**
     * 查询订单状态列表
     */
    @PreAuthorize(hasPermi = "train:orderstatus:list")
    @GetMapping("/list")
    public TableDataInfo list(TrainOrderstatus trainOrderstatus)
    {
        startPage();
        List<TrainOrderstatus> list = trainOrderstatusService.selectTrainOrderstatusList(trainOrderstatus);
        return getDataTable(list);
    }

    /**
     * 导出订单状态列表
     */
    @PreAuthorize(hasPermi = "train:orderstatus:export")
    @Log(title = "订单状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainOrderstatus trainOrderstatus) throws IOException
    {
        List<TrainOrderstatus> list = trainOrderstatusService.selectTrainOrderstatusList(trainOrderstatus);
        ExcelUtil<TrainOrderstatus> util = new ExcelUtil<TrainOrderstatus>(TrainOrderstatus.class);
        util.exportExcel(response, list, "订单状态数据");
    }

    /**
     * 获取订单状态详细信息
     */
    @PreAuthorize(hasPermi = "train:orderstatus:query")
    @GetMapping(value = "/{orderstatus}")
    public AjaxResult getInfo(@PathVariable("orderstatus") Long orderstatus)
    {
        return AjaxResult.success(trainOrderstatusService.selectTrainOrderstatusById(orderstatus));
    }

    /**
     * 新增订单状态
     */
    @PreAuthorize(hasPermi = "train:orderstatus:add")
    @Log(title = "订单状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainOrderstatus trainOrderstatus)
    {
        return toAjax(trainOrderstatusService.insertTrainOrderstatus(trainOrderstatus));
    }

    /**
     * 修改订单状态
     */
    @PreAuthorize(hasPermi = "train:orderstatus:edit")
    @Log(title = "订单状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainOrderstatus trainOrderstatus)
    {
        return toAjax(trainOrderstatusService.updateTrainOrderstatus(trainOrderstatus));
    }

    /**
     * 删除订单状态
     */
    @PreAuthorize(hasPermi = "train:orderstatus:remove")
    @Log(title = "订单状态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderstatuss}")
    public AjaxResult remove(@PathVariable Long[] orderstatuss)
    {
        return toAjax(trainOrderstatusService.deleteTrainOrderstatusByIds(orderstatuss));
    }
}
